
package com.dg.acb.utils;

import java.util.concurrent.Callable;

import android.os.AsyncTask;

public final class SimpleAsyncTask<Result> extends AsyncTask<Void, Void, Result> {
    private final Callable<Result> mCallable;
    private final Listener<Result> mListener;

    public SimpleAsyncTask(Callable<Result> callable, Listener<Result> listener) {
        mListener = listener;
        mCallable = callable;
    }

    @Override
    protected void onPostExecute(Result result) {
        mListener.onResult(result);
    }

    @Override
    protected void onCancelled() {
        mListener.onResult(null);
    }

    @Override
    protected Result doInBackground(Void... arg0) {
        try {
            return mCallable.call();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public interface Listener<Result> {
        void onResult(Result response);
    }
}
